import { defineStore } from 'pinia'
// pinia仓库写法：组合式API，选择式API写法
import { reqHospitalDetail, reqHospitalDeparment } from '@/api/hospital'
// 引入详情数据的ts类型
import type { HospitalDetailData, DepartmentResponseData, DeparmentArr } from '@/api/hospital/type.ts'
import type { DetailState } from './interface/index.ts'
import type { HospitalDetail } from '@/api/hospital/type.ts'
const useDetailStore = defineStore('Detail', {
    state: (): DetailState => {
        return {
            // 医院详情的数据
            hospitalInfo: ({} as HospitalDetail),
            // 医院科室的数据
            deparmentArr: ([] as DeparmentArr)
        }
    },
    actions: {
        // 获取医院详情的方法
        async getHospital(hoscode: string) {
            let result: HospitalDetailData = await reqHospitalDetail(hoscode)
            if (result.code == 200) {
                this.hospitalInfo = result.data
            }
        },
        // 获取医院科室的方法
        async getDeparment(hoscode: string) {
            let result: DepartmentResponseData = await reqHospitalDeparment(hoscode)
            if (result.code == 200) {
                this.deparmentArr = result.data
            }
        }
    },
    getters: {

    }
})
// 获取仓库的方法对外暴露
export default useDetailStore